﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace Cinchoo.Core.ETL
{
    [XmlRoot("csvFileLoaderTask")]
    public class ChoETLCSVFileLoaderTaskDef : ChoETLTaskDef
    {
        [ChoETLTaskDefPropertyInfo("FILE_PATH")]
        [XmlAttribute("FilePath")]
        public string FilePath;

        [ChoETLTaskDefPropertyInfo("SEPERATOR")]
        [XmlAttribute("seperator")]
        [DefaultValue(",")]
        public string Seperator;

        [ChoETLTaskDefPropertyInfo("FIRST_LINE_HEADER")]
        [XmlAttribute("firstLineHeader")]
        [DefaultValue(false)]
        public bool IsFirstLineHeader;

        [ChoETLTaskDefPropertyInfo("COMMENT_TOKENS")]
        [XmlAttribute("csvCommentTokens")]
        public string CommentTokens
        {
            get;
            set;
        }

        protected override ChoETLTask Construct(ChoETLWorkflow workflow)
        {
            ChoETLCSVFileLoaderTask task = new ChoETLCSVFileLoaderTask(FilePath, Seperator);
            task.IsFirstLineHeader = IsFirstLineHeader;
            if (!CommentTokens.IsNullOrWhiteSpace())
                task.CommentTokens = CommentTokens.SplitNTrim();

            return task;
        }
    }
}
